package com.qk.mapper;

import com.qk.dto.UserDTO;
import com.qk.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;

@Mapper
public interface UserMapper {

    List<User> selectListUsers(UserDTO userDTO);

    @Insert("INSERT INTO user(username, password, name, phone, email, gender, status, dept_id, role_id, image, remark, create_time, update_time) " + "VALUES(#{username}, #{password}, #{name}, #{phone}, #{email}, #{gender}, #{status}, #{deptId}, #{roleId}, #{image}, #{remark}, #{createTime}, #{updateTime})")
    void insertUser(User user);

    void deleteUser(List<Integer> ids);

    @Select("SELECT * FROM user WHERE id = #{id}")
    User selectUserById(Integer id);

    void updateUser(User user);

    @Select("SELECT u.*, r.label as role_name FROM user u LEFT JOIN role r ON u.role_id = r.id WHERE u.username = #{username}")
    User selectUserByUsername(String username);

    @Select("SELECT u.* FROM user u, role r WHERE u.role_id = r.id and r.label = #{roleLabel}")
    List<User> listUsersByRole(String roleLabel);

    @Select("SELECT * FROM user WHERE dept_id = #{deptId}")
    List<User> listUsersByDept(Integer deptId);

    Set<String> selectImageUrlsSince(LocalDateTime sinceTime);
}